

package q10.Visitor;

/**
 *
 * @author valicu
 */

import q10.Arbori.*;
import q10.Functii.FunctiiElementare.*;
import q10.Functii.FunctiiTrigonometrice.*;
import q10.Operatori.*;
import q10.*;

public class DerivareVisitor extends Visitor {
	private String s;

	public DerivareVisitor() {
		s = "";
	}

	public DerivareVisitor(String s) {
		this.s = s;
	}

	public String getS() {
		return s;
	}

	public void setS(String s) {
		this.s = s;
	}

	@Override
	public void visit(Plus p) {
		if (p.getfStang() != null && p.getfDrept() != null) {
			visit(p.getfStang());
			String s1 = this.s;
			visit(p.getfDrept());
			String s2 = this.s;
			s = p.concatTermeni(s1, s2);
		}
	}

	@Override
	public void visit(Minus p) {
		if (p.getfStang() != null && p.getfDrept() != null) {
			visit(p.getfStang());
			String s1 = this.s;
			visit(p.getfDrept());
			String s2 = this.s;
			s = p.concatTermeni(s1, s2);
		}
	}

	@Override
	public void visit(Cat c) {
		// TODO Auto-generated method stub

	}

	@SuppressWarnings("null")
	@Override
	public void visit(Produs p) {
		if (p.getfStang() != null && p.getfDrept() != null) {
			visit(p.getfStang());
			String f1d = this.s;
			visit(p.getfDrept());
			String f2d = this.s;

			Visitor tsv = null;
			p.getfStang().acceptVisitor(tsv);
			String f1 = ((DerivareVisitor) tsv).getS();

			p.getfDrept().acceptVisitor(tsv);
			String f2 = ((DerivareVisitor) tsv).getS();

			this.s = Plus.concatTermens(Produs.concatTermens(f1d, f2), Produs.concatTermens(f1, f2d));

		}

	}

	@Override
	public void visit(Necunoscuta n) {
		s = "1";
	}

	@Override
	public void visit(Constanta co) {
		s = "0";
	}

	@SuppressWarnings("null")
	@Override
	public void visit(Sin s) {
		if (s.getfStang() != null) {
			visit(s.getfStang());
			String fsd = this.s;
			Visitor tsv = null;
			s.getfStang().acceptVisitor(tsv);
			String fs = ((DerivareVisitor) tsv).getS();
			this.s = Produs.concatTermens(Cos.concatTermens(fs), fsd);
		}
	}

	@Override
	public void visit(Cos c) {
		// TODO Auto-generated method stub

	}

	@Override
	public void visit(Nod n) {
		// TODO Auto-generated method stub

	}

	public void visit(ArboreFunctional a) {
		// TODO Auto-generated method stub

	}

}
